import os
import sys
# 方法 1
date = """0000100010000001101010101001001100000011
0101111001111101110111100000101010011111
1000010000011101010110000000001011010100
0110101010110000000101100100000101001001
0000011010100000111111001101100010101001
0110000110000000110100000000010010100011
0100110010000110000000100010000101110000
0010011010100110001111001101100110100010
1111000111101000001110010001001011101101
0011110100011000000001101001101110100001
0000000101011000010011111001010011011100
0000100000011001000100101000111011101100
0010110000001000001010100011000010100011
0110110000100011011010011010001101011011
0000100100000001010000101100000000000010
0011001000001000000010011001100101000110
1110101000011000000100011001001100111010
0000100100111000001101001000001010010001
0100010010000110100001100000110111110101
1000001001100010011001111101011001110001
0000000010100101000000111100110010101101
0010110101001100000100000010000010110011
0000011101001001000111011000100111010100
0010001100100000011000101011000000010101
1001111010010110011010101110000000101110
0110011101000010100001000101001001100010
1101000000010010011001000100110010000101
1001100010100010000100000101111111111100
1001011010101100001000000011000110110000
0011000100011000010111101000101110110001"""
num = []
for i in date.split('\n'):
    num.append(list(i))
print(num)
nums = [(0, 1), (1, 0), (0, -1), (-1, 0)]


def dfs(x, y):
    count = 1
    num[x][y] = '2'
    ans = [(x, y)]
    while ans:
        tx, ty = ans.pop()
        for i in nums:
            dx = tx + i[0]
            dy = ty + i[1]
            if 0 <= dx <= 29 and 0 <= dy <= 39:
                if num[dx][dy] == '0':
                    num[dx][dy] = '2'
                    count += 1
                    ans.append((dx, dy))
    return count


print(dfs(0, 0))
print(num)

# 方法二
vis = [41 * [0] for i in range(31)]
matrix = ['0000100010000001101010101001001100000011', '0101111001111101110111100000101010011111', '1000010000011101010110000000001011010100', '0110101010110000000101100100000101001001', '0000011010100000111111001101100010101001', '0110000110000000110100000000010010100011', '0100110010000110000000100010000101110000', '0010011010100110001111001101100110100010', '1111000111101000001110010001001011101101', '0011110100011000000001101001101110100001', '0000000101011000010011111001010011011100', '0000100000011001000100101000111011101100', '0010110000001000001010100011000010100011', '0110110000100011011010011010001101011011', '0000100100000001010000101100000000000010', '0011001000001000000010011001100101000110', '1110101000011000000100011001001100111010', '0000100100111000001101001000001010010001', '0100010010000110100001100000110111110101', '1000001001100010011001111101011001110001', '0000000010100101000000111100110010101101', '0010110101001100000100000010000010110011', '0000011101001001000111011000100111010100', '0010001100100000011000101011000000010101', '1001111010010110011010101110000000101110', '0110011101000010100001000101001001100010', '1101000000010010011001000100110010000101', '1001100010100010000100000101111111111100', '1001011010101100001000000011000110110000', '0011000100011000010111101000101110110001']
def dfs(x,y):
  vis[x][y] = 1
  for dx,dy in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
    if 0<=dx<30 and 0<=dy < 40 and matrix[dx][dy] == "0" and vis[dx][dy] == 0:
      dfs(dx,dy)

dfs(0,0)
ans = 0
for i in range(30):
    for j in range(40):
        if vis[i][j] == 1:
            ans +=1
print(ans)